/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.dto;

import java.io.Serializable;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import com.niedziela12.pai.ejb.entities.Reservation;

/**
 *
 * @author Kamil
 */
@XmlRootElement
@XmlType(propOrder = {
    "id",
    "room",
    "user",
    "reservationBegin",
    "reservationEnd",
    "price",
    "confirmed"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class ReservationDTO implements Serializable {
    @XmlTransient
    private static final long serialVersionUID = 1L;
    @XmlElement(name = "RESERVATION_ID")
    private Long id;    
    @XmlElement(name = "ROOM")
    private RoomDTO room;    
    @XmlElement(name = "USER")
    private UserDTO user;    
    @XmlElement
    private Date reservationBegin;    
    @XmlElement
    private Date reservationEnd;
    @XmlElement
    private double price;
    @XmlElement
    private boolean confirmed;

    public ReservationDTO(){        
    }
    
    public ReservationDTO(Reservation reservation) {
        if (reservation != null) {
            this.id = reservation.getId();
            this.room = new RoomDTO(reservation.getRoom());
            this.user = new UserDTO(reservation.getUser());
            this.reservationBegin = reservation.getReservationBegin();
            this.reservationEnd = reservation.getReservationEnd();
            this.price = reservation.getPrice();
            this.confirmed = reservation.isConfirmed();
        }
    }
    
    public Reservation toReservation(){
        Reservation reservation = new Reservation();
        reservation.setId(id);
        reservation.setConfirmed(confirmed);
        reservation.setPrice(price);
        reservation.setReservationBegin(reservationBegin);
        reservation.setReservationEnd(reservationEnd);
        reservation.setRoom(room.toRoom());
        reservation.setUser(user.toUser());
        return reservation;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public RoomDTO getRoom() {
        return room;
    }

    public void setRoom(RoomDTO room) {
        this.room = room;
    }

    public UserDTO getUser() {
        return user;
    }

    public void setUser(UserDTO user) {
        this.user = user;
    }

    public Date getReservationBegin() {
        return reservationBegin;
    }

    public void setReservationBegin(Date reservationBegin) {
        this.reservationBegin = reservationBegin;
    }

    public Date getReservationEnd() {
        return reservationEnd;
    }

    public void setReservationEnd(Date reservationEnd) {
        this.reservationEnd = reservationEnd;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public boolean isConfirmed() {
        return confirmed;
    }

    public void setConfirmed(boolean confirmed) {
        this.confirmed = confirmed;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ReservationDTO)) {
            return false;
        }
        ReservationDTO other = (ReservationDTO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.niedziela12.pai.dto.Reservation[ id=" + id + " ]";
    }
    
}
